<template>
    <div class="container">
        <div class="operation-wrapper">
            <el-button
                type="primary"
                size="mini"
                :disabled="!authResult.auth_add"
                @click="handleAddUserGroup">新增</el-button>
        </div>
        <div class="content-wrapper">
            <el-table
                :data="userGroupList"
                style="width: 100%">
                <el-table-column
                    prop="title"
                    label="用户组"/>
                <el-table-column
                    label="操作">
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            :disabled="!authResult.auth_edit"
                            @click="handleEditUserGroup(scope.row.group_no)">编辑</el-button><br>
                    </template>
                </el-table-column>
            </el-table>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            authResult: {},
            userGroupList: []
        };
    },
    created() {
        this.$store.commit('SET_HEADER', [
            {
                title: '设置',
            },
            {
                title: '用户组列表'
            }
        ]);
        this.authResult = this.$route.meta.authResult;
        this.getUserGroupList();
    },
    methods: {
        /**
         * 获取用户组列表
         */
        getUserGroupList() {
            this.$post('/__local/system%5Cuser_group%5Cget_list', {}, resp => {
                if (resp.code == 1) {
                    this.userGroupList = resp.data.list;
                }
            });
        },

        /**
         * 跳转到新增用户组页面
         */
        handleAddUserGroup() {
            this.$router.push({
                name: 'UserGroupEdit'
            });
        },

        /**
         * 跳转到编辑用户组页面
         */
        handleEditUserGroup(group_no) {
            this.$router.push({
                name: 'UserGroupEdit',
                query: {
                    group_no: group_no
                }
            });
        }
    }
};
</script>

<style lang="less" scoped>
.container {
    display: flex;
    flex-direction: column;
    width: 100%;
}
.operation-wrapper {
    display: flex;
    flex-direction: row-reverse;
    padding: 12px 23px;
    background-color: #fff;
}
.content-wrapper {
    flex: 1;
    margin: 15px;
    background-color: #fff;
    overflow: auto;
}
</style>